<script>
	import { userApi } from '@/http/userApi.js';
	import { USER_TOKEN } from '@/constants/local-storage-key-const'
	import store from './store'
	export default {
		onLaunch: function() {
			this.setUserInfo()
      this.setWxHeader()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			setWxHeader(){
				let statusBarHeight = uni.getWindowInfo().statusBarHeight;
				// #ifdef MP
				let menuButtonHeight = uni.getMenuButtonBoundingClientRect().height;
				let titleBarWidth = uni.getWindowInfo().windowWidth - uni.getMenuButtonBoundingClientRect().width - (uni.getWindowInfo().windowWidth - uni.getMenuButtonBoundingClientRect().right) * 2;
				let titleBarHeight = (uni.getMenuButtonBoundingClientRect().top - statusBarHeight) * 2 + menuButtonHeight;
				store.commit('setWxHeader',{
					'statusBarHeight':statusBarHeight,
					'menuButtonHeight':menuButtonHeight,
					'titleBarWidth':titleBarWidth,
					'titleBarHeight':titleBarHeight
				})
				// #endif
				// #ifdef APP
				store.commit('setStatusBarHeight',statusBarHeight)
				// #endif
			},
			setUserInfo() {   
				const token = uni.getStorageSync(USER_TOKEN)
				if(token){
					userApi.getUserInfo().then((res)=>{
						store.commit('setUserInfo',res)
					}).catch((e)=>{
						console.log('e',e)
					})
				}
			}
		}
	}
</script>

<style>
	@import './theme/iconfont.css';
	@import './theme/index.css';
	/*每个页面公共css */
</style>
